package com.java.module.fire.controller.admin;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.java.common.lang.annotation.Log;
import com.java.common.lang.domain.AjaxResult;
import com.java.common.lang.enums.BusinessTypeEnum;
import com.java.common.utils.WebKit;
import com.java.module.fire.domain.Comment;
import com.java.module.fire.service.ICommentService;
import com.java.common.utils.poi.ExcelUtil;
import com.java.common.lang.domain.page.TableDataInfo;

/**
 * 帖子评论Controller
 * 
 * @author Administrator
 * @date 2025-02-10
 */
@RestController("AdminCommentController")
@RequestMapping("/fire/comment")
public class CommentController {
    @Autowired
    private ICommentService commentService;

    /**
     * 查询帖子评论列表
     */
    @PreAuthorize("@ss.hasPermi('fire:comment:list')")
    @GetMapping("/list")
    public TableDataInfo list(Comment comment) {
        WebKit.startPage();
        List<Comment> list = commentService.selectCommentList(comment);
        return WebKit.getDataTable(list);
    }

    /**
     * 导出帖子评论列表
     */
    @PreAuthorize("@ss.hasPermi('fire:comment:export')")
    @Log(title = "帖子评论", businessType = BusinessTypeEnum.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Comment comment) {
        List<Comment> list = commentService.selectCommentList(comment);
        ExcelUtil<Comment> util = new ExcelUtil<Comment>(Comment.class);
        return util.exportExcel(list, "comment");
    }

    /**
     * 获取帖子评论详细信息
     */
    @PreAuthorize("@ss.hasPermi('fire:comment:query')")
    @GetMapping(value = "/{commentId}")
    public AjaxResult getInfo(@PathVariable("commentId") Long commentId) {
        return AjaxResult.success(commentService.selectCommentById(commentId));
    }

    /**
     * 新增帖子评论
     */
    @PreAuthorize("@ss.hasPermi('fire:comment:add')")
    @Log(title = "帖子评论", businessType = BusinessTypeEnum.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Comment comment) {
        return WebKit.toAjax(commentService.insertComment(comment));
    }

    /**
     * 修改帖子评论
     */
    @PreAuthorize("@ss.hasPermi('fire:comment:edit')")
    @Log(title = "帖子评论", businessType = BusinessTypeEnum.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Comment comment) {
        return WebKit.toAjax(commentService.updateComment(comment));
    }

    /**
     * 删除帖子评论
     */
    @PreAuthorize("@ss.hasPermi('fire:comment:remove')")
    @Log(title = "帖子评论", businessType = BusinessTypeEnum.DELETE)
	@DeleteMapping("/{commentIds}")
    public AjaxResult remove(@PathVariable Long[] commentIds) {
        return WebKit.toAjax(commentService.deleteCommentByIds(commentIds));
    }
}
